package com.mmall.concurrency.task;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.concurrent.Callable;

/**
 * @Author:LiuWei
 * @Description:
 * @Date: Created in 17:13 2019/7/3
 * @Modified By:
 */
@Slf4j
public class IfaasSerachTask implements Callable {

    private HttpServletRequest request;


    public IfaasSerachTask(HttpServletRequest request) {
        this.request = request;
    }

    @Override
    public Boolean call() throws Exception {
        Date requestTime = (Date)request.getAttribute("requestTime");//请求时间
        Integer userNum = (Integer)request.getAttribute("userNum");
        long timeout = requestTime.getTime() + 10000L;
        if(new Date().getTime()>=timeout){
            log.info("user-{} limit",userNum);
            return false;
        }
        Thread.sleep(3000);
        if(new Date().getTime()>=timeout){
            log.info("user-{} limit",userNum);
            return false;
        }
        log.info("user-{} success",userNum);
        return true;
    }
}
